<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>


    class sayhello {
        constructor(name, say) {
            this.name = {
                "fullName":name,
                "firstName":"first",
                "lastName":"last"
            }
            this.say = say || "default-say"
        }
    }
    var persons = []
    var list = [1,2,3,4,5,6]
    list.map(function (num) {
        var people = new sayhello("liming"+num,"wo shi "+num)
        persons.push(people)
    })
    var kongtao = new sayhello("kongtao")
    console.log(persons)
    console.log(kongtao)

    /*-----------------------------------------------------------------------------------------------------*/
    /*-----------------------------------------------------------------------------------------------------*/
    var weatherData =  {
        "update": "201703081200",
        "lon": "110.5333",
        "hei": "998.6",
        "name_en": "Tu Mo Te You Qi",
        "utc": "36",
        "rh": "52.4",
        "pid": "82630",
        "rh_min": "27.4",
        "lst": "2017030920",
        "rh_max": "52.4",
        "ff_level": "0.0",
        "dd": "270.0",
        "temp_max": "8.0",
        "ff": "2.4",
        "dd_level": "6.0",
        "temp_min": "2.0",
        "weather": "0.0",
        "temp": "2.0",
        "cloud": "0.0",
        "admin_id": "150221",
        "station_id": "53455",
        "rain": "0.0",
        "name_zh": "土默特右旗",
        "lat": "40.55"
    }
    class WeatherClass {
        constructor(weatherData){
            var weatherFormat = {}
            var key = weatherData.name_zh
            weatherFormat[key] = weatherData
            return weatherFormat
        }
    }

    var weather = new WeatherClass(weatherData)
    console.log(weather)

    /*-----------------------------------------------------------------------------------------------------*/
    /*-----------------------------------------------------------------------------------------------------*/
    class Rectangle {
        constructor(length, width) {
            console.log(new.target === Rectangle);
            // ...
        }
    }
    class Square extends Rectangle {
        constructor(length) {
            super(length, length);
        }
    }
    var obj = new Square(3); //  输出 false
    /*-----------------------------------------------------------------------------------------------------*/
    /*-----------------------------------------------------------------------------------------------------*/
    function Person(name) {
        if(new.target !== undefined) {
            this.name = name;
        } else {
            throw new Error(' 必须使用 new 生成实例 ');
        }
    }
    //  另一种写法
    function Person(name) {
        if(new.target === Person) {
            this.name = name;
        } else {
            throw new Error(' 必须使用 new 生成实例 ');
        }
    }
    var person = new Person(' 张三 '); //  正确
    var notAPerson = Person.call(person, ' 张三 '); //  报错
    /*-----------------------------------------------------------------------------------------------------*/
    /*-----------------------------------------------------------------------------------------------------*/
</script>
</body>
</html>